package cn.jbit.shoppingcart.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import cn.jbit.pojo.commodity;
import cn.jbit.shoppingcart.dao.ShoppingCartMapper;
import cn.jbit.shoppingcart.service.ShoppingCartService;
/**
 * 购物车service实现层
 * @author _Cpxy
 *
 */
public class ShoppingCartServiceImpl implements ShoppingCartService{
	
	/* 购物车dao层对象 */
	@Autowired
	private ShoppingCartMapper sm;
	
	/**
	 * 查询购物车商品
	 */
	@Override
	public List<commodity> showCommodit() {
		// TODO Auto-generated method stub
		return sm.showCommodit();
	}
	
	/**
	 * 购物车添加商品
	 */
	@Override
	public void addCommodit(int commoditId,int userId,int count) {
		// TODO Auto-generated method stub
		try {
			sm.addCommodit(commoditId, userId, count);
			System.out.println("购物车添加商品成功！");
		} catch (Exception e) {
			// TODO: handle exception
			System.out.println("异常信息为："+e);
		}
		
	}

	/**
	 * 购物车删除商品
	 */
	@Override
	public void deleteCommodit(int id) {
		// TODO Auto-generated method stub
		try {
			sm.deleteCommodit(id);
			System.out.println("购物车删除商品成功！");
		} catch (Exception e) {
			// TODO: handle exception
			System.out.println("异常信息为："+e);
		}
	}

	/**
	 * 清空购物车
	 */
	@Override
	public void clearCommodit() {
		// TODO Auto-generated method stub
		try {
			sm.clearCommodit();
		} catch (Exception e) {
			// TODO: handle exception
			System.out.println("异常信息为："+e);
		}
		
	}
	
	/**
	 * 计算单个商品价格
	 */
	@Override
	public Double getTotalPrice(double money, double num) {
		// TODO Auto-generated method stub
		//总价
		Double prices = money*num;
		return prices;
	}
}
